package com.ss.android.article.base.feature.favorite;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.c.SharedPreferenceCompat;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.account.Spipe;
import com.ss.android.account.b.OnAccountRefreshListener;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.splash.SplashAdActivity;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.TabLinearLayout;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.activity.FragmentActivity;

import inline.DrawerLayoutDemo;

public class FavoriteActivity extends FragmentActivity implements OnPageChangeListener, DrawerLayoutDemo.b, OnAccountRefreshListener {
    protected View a;
    boolean b = false;
    AppData mAppData;
    boolean d = false;
    private ViewPager mViewPager;
    private CateAdapter mCateAdapter;
    private TextView g;
    private TextView h;
    private TextView i;
    private TextView j;
    private ImageView k;
    private TextView l;
    private FrameLayout m;
    private TabLinearLayout mTabLinearLayout;
    private boolean o;
    private boolean p = false;
    private Spipe mSpipe;

    private void a() {
        if (this.mViewPager != null && this.mViewPager.getCurrentItem() == 0) {
            if (!this.mSpipe.isLogin && (this.mAppData.favorFirstUnlogin)) {
                Spipe.a(this, android.support.design.a.createJumpData("title_favor", "favor_popup"));
                mAppData.favorFirstUnlogin = false;
                SharedPreferences.Editor editor = mAppData.mContext.getSharedPreferences("app_setting", 0).edit();
                editor.putBoolean("favor_first_unlogin", mAppData.favorFirstUnlogin);
                SharedPreferenceCompat.commit(editor);
            } else if (!this.mSpipe.isLogin && (this.mAppData.X)) {
                UIUtils.setVisibility(this.a, 0);
                return;
            }
            UIUtils.setVisibility(this.a, 8);
        }
    }

    static void a(FavoriteActivity arg1, String arg2) {
        MobClickCombiner.onEvent(arg1, "favorite_tab", arg2);
    }

    static boolean a(FavoriteActivity arg1) {
        arg1.o = true;
        return true;
    }

    public final void onPageScrollStateChanged(int state) {
    }

    public final void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        TabLinearLayout tabLinearLayout = this.mTabLinearLayout;
        tabLinearLayout.mCurrentPosition = position;
        tabLinearLayout.mPositionOffset = positionOffset;
        tabLinearLayout.invalidate();
    }

    public final void a(boolean isNightMode) {
        if ((isNightMode) || !this.mIsNightMode) {
            this.mRightBtn.setTextColor(this.getResources().getColorStateList(com.ss.android.article.browser.R.color.btn_common_text));
        } else {
            this.d = false;
            this.mRightBtn.setTextColor(Color.parseColor("#4b4b4b"));
        }
        UIUtils.setVisibility(mRightBtn, isNightMode ? View.VISIBLE : View.GONE);
        this.mRightBtn.setText(com.ss.android.article.browser.R.string.br);
    }

    static ViewPager b(FavoriteActivity arg1) {
        return arg1.mViewPager;
    }

    private static boolean b() {
        return AppData.getInstance().getAbSettings().isFeedClearAllRefreshEnable();
    }

    public final void onPageSelected(int position) {
        int v4 = R.color.ssxinzi4;
        int v2 = R.color.ssxinzi1;
        if (position != 0) {
            UIUtils.setVisibility(this.a, 8);
            this.d = false;
            if (this.mCateAdapter != null) {
                Fragment v0 = this.mCateAdapter.d();
                if (((v0 instanceof FavoriteArticleListFragment)) && !v0.isHidden()) {
                    ((FavoriteArticleListFragment) v0).a(this.d);
                }
            }
        }

        switch (position) {
            case 0: {
                this.g.setTextColor(ContextCompat.getColor(((Context) this), v4));
                this.h.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.i.setTextColor(ContextCompat.getColor(((Context) this), v2));
                if (FavoriteActivity.b()) {
                    this.j.setTextColor(ContextCompat.getColor(((Context) this), v2));
                }

                this.a(true);
                if (this.o) {
                    this.o = false;
                    return;
                }

                MobClickCombiner.onEvent(((Context) this), "favorite", "tab_swipe");
                break;
            }
            case 1: {
                this.g.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.h.setTextColor(ContextCompat.getColor(((Context) this), v4));
                this.i.setTextColor(ContextCompat.getColor(((Context) this), v2));
                if (FavoriteActivity.b()) {
                    this.j.setTextColor(ContextCompat.getColor(((Context) this), v2));
                }

                this.a(false);
                if (this.o) {
                    this.o = false;
                    return;
                }

                MobClickCombiner.onEvent(((Context) this), "read_history", "tab_swipe");
                break;
            }
            case 2: {
                this.g.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.h.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.i.setTextColor(ContextCompat.getColor(((Context) this), v4));
                if (FavoriteActivity.b()) {
                    this.j.setTextColor(ContextCompat.getColor(((Context) this), v2));
                }

                this.a(false);
                if (this.o) {
                    this.o = false;
                    return;
                }

                MobClickCombiner.onEvent(((Context) this), "push_history", "tab_swipe");
                break;
            }
            case 3: {
                if (!FavoriteActivity.b()) {
                    return;
                }

                this.a(false);
                this.g.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.h.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.i.setTextColor(ContextCompat.getColor(((Context) this), v2));
                this.j.setTextColor(ContextCompat.getColor(((Context) this), v4));
                if (this.o) {
                    this.o = false;
                    return;
                }

                MobClickCombiner.onEvent(((Context) this), "push_history", "tab_swipe");
                break;
            }
        }
    }

    static void c(FavoriteActivity arg0) {
        arg0.onBackBtnClick();
    }

    static TextView d(FavoriteActivity arg1) {
        return arg1.mRightBtn;
    }

    static TextView e(FavoriteActivity arg1) {
        return arg1.mRightBtn;
    }

    static CateAdapter f(FavoriteActivity arg1) {
        return arg1.mCateAdapter;
    }

    public int getDayBackgroundRes() {
        return R.color.activity_bg_color;
    }

    public int getLayout() {
        return R.layout.favorite_activity;
    }

    public int getNightBackgroundRes() {
        return R.color.activity_bg_color;
    }

    public void init() {

        super.init();
        this.mAppData = AppData.getInstance();
        this.mSpipe = Spipe.inst();
        this.mSpipe.addOnAccountRefreshListener(((OnAccountRefreshListener) this));
        this.mBackBtn.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg3) {
                FavoriteActivity.a(FavoriteActivity.this, "back_button");
                FavoriteActivity.c(FavoriteActivity.this);
            }
        });
        this.mTitleView.setText(com.ss.android.article.browser.R.string.zy);
        this.mRightBtn.setVisibility(View.VISIBLE);
        this.mRightBtn.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View view) {
                switch (FavoriteActivity.b(FavoriteActivity.this).getCurrentItem()) {
                    case 0: {
                        FavoriteActivity v1 = FavoriteActivity.this;
                        boolean v0 = !FavoriteActivity.this.d ? true : false;
                        v1.d = v0;
                        if (FavoriteActivity.this.d) {
                            MobClickCombiner.onEvent(view.getContext(), "favorite", "edit");
                            FavoriteActivity.d(FavoriteActivity.this).setText(com.ss.android.article.browser.R.string.k4);
                        } else {
                            FavoriteActivity.e(FavoriteActivity.this).setText(com.ss.android.article.browser.R.string.k6);
                        }

                        if (FavoriteActivity.f(FavoriteActivity.this) == null) {
                            return;
                        }

                        Fragment fragment = FavoriteActivity.f(FavoriteActivity.this).d();
                        if (!(fragment instanceof FavoriteArticleListFragment)) {
                            return;
                        }

                        if (fragment.isHidden()) {
                            return;
                        }
                        ((FavoriteArticleListFragment) fragment).a(FavoriteActivity.this.d);
                        break;
                    }
                }
            }
        } );
        this.a(false);
        this.k = (ImageView) this.findViewById(R.id.tip_close_btn);
        this.l = (TextView) this.findViewById(R.id.tip_login_btn);
        this.a = this.findViewById(com.ss.android.article.browser.R.id.show_login_tip);
        this.findViewById(com.ss.android.article.browser.R.id.tip_text);
        this.l.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg4) {
                FavoriteActivity.a(FavoriteActivity.this, "login_tip_banner_click");
                FavoriteActivity.this.b = true;
                ComponentsManifest.findComponent(com.ss.android.account.v2.bb.class)
                        .startAccountLoginActivity(
                                FavoriteActivity.this,
                                android.support.design.a.createJumpData("title_favor", "favor_bottom"));
            }
        });
        this.k.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FavoriteActivity.this.a.setVisibility(View.GONE);
                FavoriteActivity.a(FavoriteActivity.this, "login_tip_banner_close");
                FavoriteActivity.this.mAppData.X = false;
            }
        });
        this.m = (FrameLayout) this.findViewById(R.id.favorite_article);
        if (FavoriteActivity.b()) {
            this.m.removeAllViews();
            this.m.addView(LayoutInflater.from(this.getApplicationContext()).inflate(com.ss.android.article.browser.R.layout.d9, null));
        }

        this.mTabLinearLayout = (TabLinearLayout) this.findViewById(R.id.i9);
        this.g = (TextView) this.findViewById(R.id.sn);
        this.g.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FavoriteActivity.this.o = true;
                FavoriteActivity.this.mViewPager.setCurrentItem(0);
                MobClickCombiner.onEvent(view.getContext(), "favorite", "tab_click");
            }
        });
        this.h = (TextView) this.findViewById(R.id.so);
        this.h.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View v) {
                FavoriteActivity.a(FavoriteActivity.this);
                FavoriteActivity.b(FavoriteActivity.this).setCurrentItem(1);
                MobClickCombiner.onEvent(v.getContext(), "read_history", "tab_click");
            }
        });
        this.i = (TextView) this.findViewById(R.id.sp);
        this.i.setOnClickListener(new View.OnClickListener() {

            public final void onClick(View arg4) {
                FavoriteActivity.a(FavoriteActivity.this);
                FavoriteActivity.b(FavoriteActivity.this).setCurrentItem(2);
                MobClickCombiner.onEvent(arg4.getContext(), "push_history", "tab_click");
            }
        });
        this.j = (TextView) this.findViewById(R.id.sz);
        if (this.j != null) {
            this.j.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View v) {
                    FavoriteActivity.a(FavoriteActivity.this);
                    FavoriteActivity.b(FavoriteActivity.this).setCurrentItem(3);
                }
            });
        }

        this.mViewPager = (ViewPager) this.findViewById(R.id.sr);
        this.mViewPager.setOffscreenPageLimit(2);
        this.mRightBtn.setPadding(((int) UIUtils.dp2px(this.mRightBtn.getContext(), 7f)), this.mRightBtn.getPaddingTop(), ((int) UIUtils.dp2px(this.mRightBtn.getContext(), 15f)), this.mRightBtn.getPaddingBottom());
        Intent intent = this.getIntent();
        final int position;
        if (intent != null) {
            if (intent.getBooleanExtra("from_notification", false)) {
                this.p = true;
            }
            position = intent.getIntExtra("bundle_position", 0);
        } else {
            position = 0;
        }

        this.o = true;
        this.mCateAdapter = new CateAdapter(this.getSupportFragmentManager(), this.mViewPager, this);
        this.mViewPager.setAdapter(this.mCateAdapter);
        this.mViewPager.setCurrentItem(position);
        this.mViewPager.setOffscreenPageLimit(3);
        this.mViewPager.addOnPageChangeListener(this);
        this.mViewPager.post(new Runnable() {
            @Override
            public final void run() {
                FavoriteActivity.this.onPageSelected(position);
            }
        });
        this.a();
    }

    public void onAccountRefresh(boolean arg3, int arg4) {
        if ((this.isViewValid()) && (arg3)) {
            this.a();
            if (this.b) {
                this.b = false;
                MobClickCombiner.onEvent(((Context) this), "favorite_tab", "login_tip_banner_success");
            }
        }
    }

    public void onBackPressed() {
        if (!this.isFinishing()) {
            Intent v0 = null;
            if (this.isTaskRoot()) {
                v0 = ToolUtils.getLaunchIntentForPackage(((Context) this), this.getPackageName());
            }

            this.finish();
            if (v0 == null) {
                return;
            }

            this.startActivity(v0);
        }
    }

    public void onDestroy() {
        this.mSpipe.b(((OnAccountRefreshListener) this));
        super.onDestroy();
    }

    public void onNewIntent(Intent arg3) {
        if (arg3 != null && (arg3.getBooleanExtra("from_notification", false))) {
            this.p = true;
        }
    }

    public void onResume() {
        super.onResume();
        SplashAdActivity.a(((Context) this), this.p);
        this.p = false;
    }
}

